package com.project.restaurant.thirdpart.controller;

import com.project.restaurant.common.api.ResponseResult;
import com.project.restaurant.common.api.ServiceReturn;


import com.project.restaurant.common.api.ServiceStateCode;
import com.project.restaurant.thirdpart.mail.AttachFileMail;
import com.project.restaurant.thirdpart.mail.Mail;
import com.project.restaurant.thirdpart.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mail")
public class MailController {

    @Autowired
    MailService service;

    @GetMapping("/test")
    public String test(){
        System.out.println("成功");
        return "成功!";
    }

    @PostMapping(value = "/send/simpleMail")
    public ResponseResult<Boolean> sendSimpleMail(@RequestBody @Validated Mail mail){
        ServiceReturn<Boolean> result = service.sendSimpleMail(mail);
        return ResponseResult.auto(result.getStateCode(),result.getReturnData());
    }

    @PostMapping(value = "/send/attachFileMail")
    public ResponseResult<Boolean> sendAttachFileMail(@RequestBody @Validated AttachFileMail mail){
        ServiceReturn<Boolean> result = service.sendAttachFileMail(mail);
        return ResponseResult.auto(result.getStateCode(),result.getReturnData());
    }

    @PostMapping(value = "/send/templateMail")
    public ResponseResult<Boolean> sendTemplateMail(@RequestBody @Validated Mail mail){
        ServiceReturn<Boolean> result = service.sendTemplateMail(mail);
        return ResponseResult.auto(result.getStateCode(),result.getReturnData());
    }





}
